using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-10-09
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 扫码枪配置表
    /// </summary>
    [Verify]
    [Route("run/scannerconfig")]
    [ApiExplorerSettings(GroupName = "business")]
    public class ScannerConfigController : BaseController
    {
        /// <summary>
        /// 扫码枪配置表接口
        /// </summary>
        private readonly IScannerConfigService _ScannerConfigService;

        public ScannerConfigController(IScannerConfigService ScannerConfigService)
        {
            _ScannerConfigService = ScannerConfigService;
        }

        /// <summary>
        /// 查询扫码枪配置表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "run:scannerconfig:list")]
        public IActionResult QueryScannerConfig([FromQuery] ScannerConfigQueryDto parm)
        {
            var response = _ScannerConfigService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询扫码枪配置表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "run:scannerconfig:query")]
        public IActionResult GetScannerConfig(int Id)
        {
            var response = _ScannerConfigService.GetInfo(Id);

            var info = response.Adapt<ScannerConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加扫码枪配置表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "run:scannerconfig:add")]
        [Log(Title = "扫码枪配置表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddScannerConfig([FromBody] ScannerConfigDto parm)
        {
            var modal = parm.Adapt<ScannerConfig>().ToCreate(HttpContext);

            var response = _ScannerConfigService.AddScannerConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新扫码枪配置表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "run:scannerconfig:edit")]
        [Log(Title = "扫码枪配置表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateScannerConfig([FromBody] ScannerConfigDto parm)
        {
            var modal = parm.Adapt<ScannerConfig>().ToUpdate(HttpContext);
            var response = _ScannerConfigService.UpdateScannerConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除扫码枪配置表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "run:scannerconfig:delete")]
        [Log(Title = "扫码枪配置表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteScannerConfig([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_ScannerConfigService.Delete(idArr));
        }
    }
}